<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
    <title>后台管理 | 商品管理</title>
    <meta charset="utf-8">
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/static/images/favicon.ico" type="image/x-icon" >
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script>
        function search() {
            var kw = $("#kw").val();
            if(kw)
                window.location="${pageContext.request.contextPath}/admin/searchProduct/"+kw;
        }
    </script>
</head>
<body>
<div class="container">
    <nav class="navbar navbar-expand-sm">
        <ul class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link active" href="${pageContext.request.contextPath}/admin//manageProduct/1">商品管理</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="${pageContext.request.contextPath}/admin//manageNote/1">评论区管理</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="${pageContext.request.contextPath}/admin//managePerson/1">用户管理</a>
            </li>
        </ul>
        <ul class="nav ml-auto">
            <c:choose>
                <c:when test="${empty sessionScope.id}">
                    <li class="nav-item">
                        <a class="nav-link btn btn-outline-primary"
                           href="${pageContext.request.contextPath}/user/login">登录</a>
                    </li>
                </c:when>
                <c:otherwise>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">${sessionScope.user}</a>
                        <div class="dropdown-menu">
                            <a class="dropdown-item" onclick="showFrame('${pageContext.request.contextPath}/user/modify/',500,400)">修改个人信息</a>
                            <a class="dropdown-item" href="${pageContext.request.contextPath}/user/logout">登出</a>
                        </div>
                    </li>
                </c:otherwise>
            </c:choose>
            <li class="nav-item">
                <a target="_blank" class="nav-link btn btn-outline-primary btn-sm"
                   href="${pageContext.request.contextPath}/">首页</a>
            </li>
        </ul>
    </nav>
<hr/>
    <div class="card bg-light text-dark">
        <div class="card-body">
            <div class="form-inline float-left">
                <input id="kw" name="kw" class="form-control" type="text" placeholder="关键字">
                <button class="btn btn-success" type="submit" onclick="search()" value="${kw}">搜索</button>
            </div>
            <small id="sm-info" class="text-danger"></small>
            <a onclick="showFrame('${pageContext.request.contextPath}/admin/addProduct.jsp',900,600)" class="btn btn-outline-primary float-right">添加</a>
        </div>
    </div>

    <table class="table table-hover">
        <thead>
        <tr>
            <th>商品编号</th>
            <th>商品名称</th>
            <th>商品商标</th>
            <th>商品型号</th>
            <th>商品价格</th>
            <th class="text-center">操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${list}" var="product">
        <tr>
            <td>${product.serialNumber}</td>
            <td>${product.name}</td>
            <td>${product.brand}</td>
            <td>${product.model}</td>
            <td>${product.price}</td>
            <td class="text-center">
                <a class="btn-warning btn-sm"
                   onclick="showFrame('${pageContext.request.contextPath}/admin/modifyProduct/${product.productID}',900)">修改</a>
                &nbsp;
                <a class="text-light btn-danger btn-sm"
                   onclick="showFrame('${pageContext.request.contextPath}/admin/deleteProduct/${product.productID}',100)">删除</a>
            </td>
        </tr>
        </c:forEach>
    </table>

    <div>
        <ul id="page_list" class="pagination justify-content-center" style="margin-top: 10px">

        </ul>
    </div>
</div>
<c:if test="${not empty count}">
    <script src="${pageContext.request.contextPath}/static/js/pagination.js"></script>
    <script>
        var count = ${count};
        pagination($("#page_list"),${page},Math.ceil(count/10), "${pageContext.request.contextPath}/admin/manageProduct/");
    </script>
</c:if>
<script src="${pageContext.request.contextPath}/static/js/showFrame.js"></script>
</body>
</html>
